package com.ctgu.蓝桥杯真题.B组2019;

import java.io.*;

/**
 * @author: Backdiy
 * @data: 2021/4/10 16:10
 * @desc:
 */
public class F特别数的和 {
    public static void main(String[] args) throws IOException {
        int n = Input.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            String s = String.valueOf(i);
            sum = (s.contains("2") || s.contains("0") || s.contains("1") || s.contains("9")) ? sum + i : sum;
        }
        Input.out.println(sum);
        Input.out.flush();
    }

    static class Input {
        static StreamTokenizer streamTokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        static PrintWriter out = new PrintWriter((new OutputStreamWriter(System.out)));
        static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        static int nextInt() throws IOException {
            streamTokenizer.nextToken();
            return (int) streamTokenizer.nval;
        }

        static double nextDouble() throws IOException {
            streamTokenizer.nextToken();
            return streamTokenizer.nval;
        }

        static long nextLong() throws IOException {
            streamTokenizer.nextToken();
            return (long) streamTokenizer.nval;
        }

        static String nextLine() throws IOException {
            return bufferedReader.readLine();
        }

        static char next() throws IOException {
            return (char) bufferedReader.read();
        }
    }
}
